package com.asiainfo.dacp.datastash.open.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.asiainfo.dacp.datastash.domain.unitmonitor.repos.DataStashBrokerRepository;
import com.asiainfo.dacp.datastash.orm.po.core.DataStashBrokerPo;


@RestController
@RequestMapping("/open/datastash")
public class DataStashClusterMonitorController {
	
	@Autowired
	private DataStashBrokerRepository dataStashBrokerRepository;
	
	@RequestMapping(value = "unit_monitor/clustermonitor" , method = RequestMethod.GET)
	public @ResponseBody List<DataStashBrokerPo> getDataStashClusterMonitors(){
		List<DataStashBrokerPo> list = dataStashBrokerRepository.findAll();
		return list;
	}
	
	@RequestMapping(value = "unit_monitor/querymonitor",method = RequestMethod.GET)
	public @ResponseBody List<DataStashBrokerPo> queryBroker(
			@RequestParam(value = "brokerIp") String brokerIp,
			@RequestParam(value = "isAlive") String isAlive
			){
				List<DataStashBrokerPo> list = null;
				if(!("".equals(brokerIp)) & !("".equals(isAlive))){
					list = dataStashBrokerRepository.findByBrokerIpAndState(brokerIp, isAlive);
				}else{
					list = dataStashBrokerRepository.findByBrokerIp(brokerIp, isAlive);
				}
				return list;
		
	}
	
}
